<template>
	<div class="web-view-box" :style="'height:'+windowH+'px'">
		<web-view class="web-view" :src="url" @message="getMessage" allow="microphone;camera"></web-view>
	</div>
</template>

<script>
	import {
		HTTP_REQUEST_URL
	} from '@/config/app';
	import {
		getconfig
	} from "@/api/public";
	import {
		configMap
	} from "@/utils";
	import {
		stringify
	} from 'querystring';
	import {
		mapGetters
	} from "vuex";
	import {
		chatEndIllegal
	} from '@/api/inquiry.js';
	import Cache from '@/utils/cache.js'
	export default {
		computed: {
			...configMap(['hide_mer_status'], mapGetters(['isLogin', 'viewColor', 'uid', 'token','routeError'])),
			windowH() {
				return uni.getSystemInfoSync().windowHeight;
			},
		},
		data() {
			return {
				url: '',
				isDoctor:false,
				conversation_id:0,
			}
		},
		onLoad(option) {
			
			if(this.routeError) {
				this.$store.commit('GO_ERROR');
				return
			}
			
			//console.log("rk===>[h5===]" + JSON.stringify(option));
			this.getconfig(option);
			
			this.conversation_id = option.conversation_id || 0
			if (option.role && option.role == 'doctor') {
				this.isDoctor = true;
			}
			// #ifndef H5
			uni.setKeepScreenOn({
				keepScreenOn: true
			});
			// #endif
			
			// #ifdef APP
			this.$util.requestRtcPermission();
			// #endif
			
		},
		onUnload(options) {
			console.log("rk===>[h5===onUnload]");
			/*
			//this.$Cache.set('RTC_FLAG','rtc_ing');
			let rtcFlag = Cache.get('RTC_FLAG') || '';
			rtcFlag = uni.getStorageSync('RTC_FLAG') || '';
			console.log("rk===>[h5===onUnload-flag]"+rtcFlag);
			
			if(rtcFlag != 'rtc_ing'){
				return;
			}
			Cache.set('RTC_FLAG','rtc_end');
			let alertStr = '通话异常结束,请联系医生重新发起';
			if(this.isDoctor){
				alertStr = '通话异常结束,请重新发起';
			}
			let that = this;
			setTimeout(()=>{
				uni.showModal({
					title: '提示',
					content: alertStr,
					showCancel: false,
					success: function(res) {
						that.chatEndIllegal();
					}
				});
			},100);
			*/
		    this.chatEndIllegal();
			// #ifndef H5
			uni.setKeepScreenOn({
				keepScreenOn: false
			});
			// #endif
		},
		
		methods: {
			getconfig(option) {
				getconfig().then(res => {
					let site_url = res.data.site_url;
					this.urlDeal(option, site_url);
				}).catch(res => {
					this.$util.Tips({
						title: res
					});
				});
			},
			urlDeal(option, site_url) {
				if (!site_url) {
					return this.$util.Tips({
						title: '网站配置信息不存在,请联系管理'
					});
				}
				// 本地测试
				let preUrl = 'https://localhost:8080/'
				// 服务器地址
				// rk_warning
				 preUrl = site_url;
				this.url = preUrl + 'pages/chat/customer_list/chat?from=h5&uid=' +
					this.uid +
					'&token=' + this.token +
					'&hide_mer_status=' + this.hide_mer_status +
					'&isLogin=' + this.isLogin +
					'&viewColor=' + stringify(this.viewColor)
				if (option) {
					this.url = this.url + '&' + stringify(option);
				}
			},
			/**
			 * 结束通话【非正常结束,重置状态】
			 */
			chatEndIllegal() {
				let postDic = {
					conversation_id: this.conversation_id,
				}
				chatEndIllegal(postDic).then(res => {

				}).catch(res => {
					
				});
			},
			getMessage(data){
				
			},
		}

	}
</script>

<style lang="scss">
</style>





<!-- onLoad(option) {
 	let self = this
 	this.toUid = option.uid || 0;
 	this.productId = parseInt(option.productId) || 0;
 	this.presellId = parseInt(option.presellId) || 0;
 	this.combinationId = parseInt(option.combinationId) || 0;
 	this.orderId = option.order_id || ""
 	this.mer_id = option.mer_id || 0
 	this.refund_order_id = option.refund_order_id || 0
 	this.userId = option.userId || 0
 	if (option.role && option.role == 'doctor') {
 		this.isDoctor = true;
 		console.log("rk===>[isDoctor]");
 	}
 
 	// 问诊会话id
 	this.conversation_id = option.conversation_id || 0
 	this.conversation_status = option.conversation_status || 0;
 	this.patient_id = option.patient_id || 0;
 	//console.log('rk===>[问诊商家id:]'+this.mer_id);
 	if (option.send_tips) {
 		this.send_tips = option.send_tips;
 	}
 	if (option.conversition_type) {
 		this.conversition_type = option.conversition_type;
 	}
 	if (option.can_refund) {
 		this.can_refund = option.can_refund;
 	}
 
 	let roleStr = '';
 	if (this.isDoctor == 1) {
 		roleStr = '&role=doctor';
 	}
 	
 	let preUrl = 'https://localhost:8080';
 	// preUrl = HTTP_REQUEST_URL;
 	
 	this.url = preUrl + '/pages/chat/customer_list/chat?conversation_id=' +
 		this.conversation_id +
 		'&conversation_status=' + this.conversation_status +
 		'&mer_id=' + this.mer_id +
 		roleStr +
 		'&conversition_type=' + this.conversition_type +
 		'&can_refund=' + this.can_refund +
 		'&uid=' + this.uid +
 		'&token=' + this.token +
 		'&hide_mer_status=' + this.hide_mer_status +
 		'&isLogin=' + this.isLogin +
 		'&viewColor=' + this.viewColor
 }, -->
